﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _07_ConvertBetweenRandomSystems
{
    class Program
    {
        static string ConvertFromDecimalToRandom(int number, int numberOfSystem)
        {
            StringBuilder convertedNumber = new StringBuilder();
            while (number > 0)
            {
                switch (number % numberOfSystem)
                {
                    case 10:
                        convertedNumber.Append('A');
                        break;
                    case 11:
                        convertedNumber.Append('B');
                        break;
                    case 12:
                        convertedNumber.Append('C');
                        break;
                    case 13:
                        convertedNumber.Append('D');
                        break;
                    case 14:
                        convertedNumber.Append('E');
                        break;
                    case 15:
                        convertedNumber.Append('F');
                        break;

                    default:
                        convertedNumber.Append(number % numberOfSystem);
                        break;
                }
                number /= numberOfSystem;
            }           

            for (int index = 0; index < convertedNumber.Length / 2; index++)
            {
                char swapValue = convertedNumber[index];
                convertedNumber[index] = convertedNumber[convertedNumber.Length - index - 1];
                convertedNumber[convertedNumber.Length - index - 1] = swapValue;
            }
            return convertedNumber.ToString();
        
        }
       
        static int ConvertFromRandomToDecimal(string binaryNumber, int numberOfSystem)
        {
            int currentPower = 0;
            int decimalNumber = 0;

            while (binaryNumber.Length > currentPower)
            {
                char a = binaryNumber[binaryNumber.Length - currentPower - 1];
                int currentDigitValue = 0;
                switch (a)
                {
                    case 'A':
                        currentDigitValue = 10;
                        break;
                    case 'B':
                        currentDigitValue = 11;
                        break;
                    case 'C':
                        currentDigitValue = 12;
                        break;
                    case 'D':
                        currentDigitValue = 13;
                        break;
                    case 'E':
                        currentDigitValue = 14;
                        break;
                    case 'F':
                        currentDigitValue = 15;
                        break;
                    default:
                        currentDigitValue = (int)a - 48;
                        break;
                }
                decimalNumber += currentDigitValue * (int)Math.Pow(numberOfSystem, currentPower);
                currentPower++;
            }
            return decimalNumber;
        }
        static void Main(string[] args)
        {
            Console.WriteLine(ConvertFromDecimalToRandom(2735, 16));

        }
    }
}
